#include "threadPool.h"

// 初始化tcp连接
int initTcpSocket(int *socket_fd, char *ip, char *port)
{
  *socket_fd = socket(AF_INET, SOCK_STREAM, 0);

  int reuse = 1;
  int res1 = setsockopt(*socket_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
  ERROR_CHECK(res1, -1, "setsockopt");

  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = inet_addr(ip);
  addr.sin_port = htons(atoi(port));
  int res2 = bind(*socket_fd, (struct sockaddr *)&addr, sizeof(addr));
  ERROR_CHECK(res2, -1, "bind");

  listen(*socket_fd, 10);

  return 0;
}